﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using FangDuShi_Admin.DBUtility;
using System.Collections.Generic;//Please add references
namespace FangDuShi_Admin.DAL
{
    /// <summary>
    /// 数据访问类:HSVersionPC
    /// </summary>
    public partial class HSVersionPC
    {
        public HSVersionPC()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(decimal FID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from t_HSVersionPC");
            strSql.Append(" where FID=@FID");
            SqlParameter[] parameters = {
					new SqlParameter("@FID", SqlDbType.Decimal)
			};
            parameters[0].Value = FID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public decimal Add(FangDuShi_Admin.Model.HSVersionPC model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_HSVersionPC(");
            strSql.Append("FVersionNo,FPubDate,FIsMustUpdate,FContent)");
            strSql.Append(" values (");
            strSql.Append("@FVersionNo,@FPubDate,@FIsMustUpdate,@FContent)");
            strSql.Append(";select IDENT_CURRENT('t_HSVersionPC')");
            SqlParameter[] parameters = {
					new SqlParameter("@FVersionNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FPubDate", SqlDbType.DateTime),
					new SqlParameter("@FIsMustUpdate", SqlDbType.NVarChar,1),
					new SqlParameter("@FContent", SqlDbType.NVarChar,-1)};
            parameters[0].Value = model.FVersionNo;
            parameters[1].Value = model.FPubDate;
            parameters[2].Value = model.FIsMustUpdate;
            parameters[3].Value = model.FContent;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToDecimal(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(FangDuShi_Admin.Model.HSVersionPC model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_HSVersionPC set ");
            strSql.Append("FVersionNo=@FVersionNo,");
            strSql.Append("FPubDate=@FPubDate,");
            strSql.Append("FIsMustUpdate=@FIsMustUpdate,");
            strSql.Append("FContent=@FContent");
            strSql.Append(" where FID=@FID");
            SqlParameter[] parameters = {
					new SqlParameter("@FVersionNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FPubDate", SqlDbType.DateTime),
					new SqlParameter("@FIsMustUpdate", SqlDbType.NVarChar,1),
					new SqlParameter("@FContent", SqlDbType.NVarChar,-1),
					new SqlParameter("@FID", SqlDbType.Decimal,13)};
            parameters[0].Value = model.FVersionNo;
            parameters[1].Value = model.FPubDate;
            parameters[2].Value = model.FIsMustUpdate;
            parameters[3].Value = model.FContent;
            parameters[4].Value = model.FID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(decimal FID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_HSVersionPC ");
            strSql.Append(" where FID=@FID");
            SqlParameter[] parameters = {
					new SqlParameter("@FID", SqlDbType.Decimal)
			};
            parameters[0].Value = FID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string FIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_HSVersionPC ");
            strSql.Append(" where FID in (" + FIDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public string DelVerList(List<string> ids)
        {

            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();
            try
            {


                foreach (string s in ids)
                {

                    strSql = new StringBuilder();
                    cmds = new CommandInfo();
                    strSql.Append("delete from t_HSVersionPC ");
                    strSql.Append(" where FID=@FID");
                    SqlParameter[] parameters = {
					new SqlParameter("@FID", SqlDbType.Decimal)
			};
                    parameters[0].Value = s;


                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters;
                    cmdList.Add(cmds);



                }
                if (cmdList.Count > 0)
                {
                    DbHelperSQL.ExecuteSqlTranWithString(cmdList, 1800);
                    return "ok";
                }
            }
            catch (System.Exception ex)
            {




                return ex.Message;

            }
            return "错误";
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FangDuShi_Admin.Model.HSVersionPC GetModel(decimal FID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FID,FVersionNo,FPubDate,FIsMustUpdate,FContent from t_HSVersionPC ");
            strSql.Append(" where FID=@FID");
            SqlParameter[] parameters = {
					new SqlParameter("@FID", SqlDbType.Decimal)
			};
            parameters[0].Value = FID;

            FangDuShi_Admin.Model.HSVersionPC model = new FangDuShi_Admin.Model.HSVersionPC();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FangDuShi_Admin.Model.HSVersionPC DataRowToModel(DataRow row)
        {
            FangDuShi_Admin.Model.HSVersionPC model = new FangDuShi_Admin.Model.HSVersionPC();
            if (row != null)
            {
                if (row["FID"] != null && row["FID"].ToString() != "")
                {
                    model.FID = decimal.Parse(row["FID"].ToString());
                }
                if (row["FVersionNo"] != null)
                {
                    model.FVersionNo = row["FVersionNo"].ToString();
                }
                if (row["FPubDate"] != null && row["FPubDate"].ToString() != "")
                {
                    model.FPubDate = DateTime.Parse(row["FPubDate"].ToString());
                }
                if (row["FIsMustUpdate"] != null)
                {
                    model.FIsMustUpdate = row["FIsMustUpdate"].ToString();
                }
                if (row["FContent"] != null)
                {
                    model.FContent = row["FContent"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FID,FVersionNo,FPubDate,FIsMustUpdate,FContent ");
            strSql.Append(" FROM t_HSVersionPC ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" FID,FVersionNo,FPubDate,FIsMustUpdate,FContent ");
            strSql.Append(" FROM t_HSVersionPC ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM t_HSVersionPC ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.FID desc");
            }
            strSql.Append(")AS Row, T.*  from t_HSVersionPC T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_HSVersionPC";
            parameters[1].Value = "FID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

